<?php

namespace App\Http\Middleware;

use Closure;
use App\Common\ApiToken;


class CheckTokenAll
{
    /**
     * Handle an incoming request.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  \Closure  $next
     * @return mixed
     */
    public function handle($request, Closure $next)
    {
        //1.检查是否缺少token
        $token = $request->header('Authorization','');

        $apiToken   = new ApiToken();
        if($apiToken->check_token($token) == false)
        {
            return apiData()->send($apiToken->code,$apiToken->error);
        }
        $request->offsetSet("tokenUserId",$apiToken->tokenInfo->user_id);
        return $next($request);
    }
}
